<template>
  <el-upload
    :action="baseApi + action"
    :headers="headers"
    :show-file-list="false"
    :on-success="uploadSuccess"
    :on-error="uploadFail"
    v-bind="$attrs"
    :accept="accept"
    style="display: inline-block"
  >
    <el-button
      type="primary"
      icon="el-icon-upload"
    >{{ $t("import") }}</el-button>
  </el-upload>
</template>
<script>
import { mapGetters } from 'vuex'
import { getToken } from '@/utils/auth'

export default {
  name: 'UploadBtn',
  props: {
    action: {
      type: String,
      default: ''
    },
    accept: {
      type: String,
      default: '.xlsx'
    },
    uploadSuccess: {
      type: Function,
      default: function() {}
    },
    uploadFail: {
      type: Function,
      default: function() {}
    }
  },
  data() {
    return {
      headers: {
        Token: getToken()
      }
    }
  },
  computed: {
    ...mapGetters(['baseApi'])
  }
}
</script>

